<?php
/**
 * Created by PhpStorm.
 * User: Acer
 * Date: 2022/7/30
 * Time: 22:59
 */

namespace app\admin\controller;

use app\admin\service\BannerService;
use app\core\MyController as MyController;

class Banner extends MyController
{
    protected $noNeedAction = []; // 不需要校验控制器，通道
    // 操作前置
    protected $beforeActionList = ['my_initialize'];

    // 操作前置方法
    public function my_initialize()
    {
//        $this->is_admin();  // 权限检查
    }

    // 获取banner列表
    public function get_list(){
        $BannerService =  new BannerService();
        $res = $BannerService->s_get_list();
         _action_result(200,$res ? $res : [] ,'操作成功！');
    }

    // 新增banner
    public function add_banner(){
        $data = input();
        if(empty($data['img'])) json_err( -201);
        $res = (new BannerService())->s_add_banner($data);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }

    // 修改banner
    public function modify_banner(){
        $data = input();
        if(empty($data['bid']) || empty($data['img'])) json_err( -201);
        (new BannerService())->s_modify_banner($data);
         _action_result(200,[],'操作成功！');
    }

    // 删除banner
    public function del_banner(){
        $data = input();
        if(empty($data['bid'])) json_err( -201);
        $res = (new BannerService())->s_del_banner($data['bid']);
        if($res) _action_result(200,[],'操作成功！');
        json_err( -205);
    }

}